<%#
 Copyright 2016 Chen RuiWei <crwbak@gmail.com>
 Copyright 2018 Lienol
 Licensed to the public under the Apache License 2.0.
-%>

<% include("cbi/map") %>
<script type="text/javascript">//<![CDATA[
	XHR.get('<%=luci.dispatcher.build_url("admin", "vpn", "passwall", "status")%>', null,
		function(x, result)
		{
			var status = document.getElementsByClassName('passwall_status');
			status[0].innerHTML = result.ss_redir?'<font color=green><%=translate("RUNNING")%> ✓</font>':'<font color=red><%=translate("NOT RUNNING")%> X</font>';
		}
	);
	XHR.get('<%=luci.dispatcher.build_url("admin", "vpn", "passwall", "hrstatus")%>', null,
		function(x, result)
		{
			var haproxys = document.getElementsByClassName('hrstatus');
			haproxys[0].innerHTML = result.hrstatus?'<font color=green><%=translate("RUNNING")%> ✓</font>':'<font color=red><%=translate("NOT RUNNING")%> X</font>';
		}
	);
	XHR.get('<%=luci.dispatcher.build_url("admin", "vpn", "passwall", "kcpstatus")%>', null,
		function(x, result)
		{
			var kcps = document.getElementsByClassName('kcpstatus');
			kcps[0].innerHTML = result.kcpstatus?'<font color=green><%=translate("RUNNING")%> ✓</font>':'<font color=red><%=translate("NOT RUNNING")%> X</font>';
		}
	);
	XHR.get('<%=luci.dispatcher.build_url("admin", "vpn", "passwall", "china")%>', null,
		function(x, result)
		{
			var chinas = document.getElementsByClassName('china_status');
			chinas[0].innerHTML = result.china?'<font color=green><%=translate("working...")%> ✓</font>':'<font color=red><%=translate("Problem detected!")%> X</font>';
		}
	);
	XHR.get('<%=luci.dispatcher.build_url("admin", "vpn", "passwall", "foreign")%>', null,
		function(x, result)
		{
			var foreigns = document.getElementsByClassName('foreign_status');
			foreigns[0].innerHTML = result.foreign?'<font color=green><%=translate("working...")%> ✓</font>':'<font color=red><%=translate("Problem detected!")%> X</font>';
		}
	);
	var pings = document.getElementsByClassName('pingtime');
	for(var i = 0; i<pings.length; i++)
	{
		XHR.get('<%=luci.dispatcher.build_url("admin", "vpn", "passwall", "ping")%>', {index: i, domain: pings[i].getAttribute("hint")},
			function(x, result)
			{
				pings[result.index].innerHTML = (result.ping?result.ping:"--") + " ms";
			}
		);
	}
//]]>
</script>
